package com.gjzhao.fmmall.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.gjzhao.fmmall.dao.UserAddrMapper;
import com.gjzhao.fmmall.entity.UserAddr;
import com.gjzhao.fmmall.service.UserAddrService;
import com.gjzhao.fmmall.vo.ResponseResultVO;
import com.gjzhao.fmmall.vo.RespCode;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @Description: 用户地址 ServiceImpl
 * @Author: gjzhao
 * @Date Created in 2022-01-05 10:22 下午
 */
@Service
public class UserAddrServiceImpl implements UserAddrService {

    @Autowired
    UserAddrMapper userAddrMapper;

    /**
     * 获取用户收获地址列表信息
     * @param userId
     * @return
     */
    @Override
    public ResponseResultVO listUserAddr(String userId) {
        Example example = new Example(UserAddr.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        criteria.andEqualTo("status", 1);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);

        if (CollectionUtil.isEmpty(userAddrs) || userAddrs.size() == 0) {
            return new ResponseResultVO(RespCode.SUCCESS.getCode(), "无购物车信息", null);
        } else {
            return new ResponseResultVO(RespCode.SUCCESS.getCode(), "success", userAddrs);
        }
    }
}
